<template>
  <section class="my-runlegdetail">
    <div class="status flex flex-between flex-middle">
      <span class="font1">任务状态</span>
      <span class="font1">{{info.orderStatus === 5 ? '已完成' : '进行中'}}</span>
    </div>
    <div class="info">
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" :src="iconInfo.icon9" alt="icon" />
            <span class="font1">任务类型</span>
          </van-col>
          <van-col span="14">
            <span class="font1">跑腿</span>
          </van-col>
        </van-row>
      </div>
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" :src="iconInfo.icon3" alt="icon" />
            <span class="font1">任务名称</span>
          </van-col>
          <van-col span="14">
            <span class="font1">{{info.taskName}}</span>
          </van-col>
        </van-row>
      </div>
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" :src="iconInfo.icon4" alt="icon" />
            <span class="font1">任务金额</span>
          </van-col>
          <van-col span="14">
            <span class="price">{{info.orderAmt}}</span>
            <span class="font1">元</span>
          </van-col>
        </van-row>
      </div>
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" :src="iconInfo.icon7" alt="icon" />
            <span class="font1">联系人</span>
          </van-col>
          <van-col span="14">
            <span class="font1">{{info.linkMan}}</span>
          </van-col>
        </van-row>
      </div>
      <div v-if="info.linkTel">
        <van-row>
          <van-col span="10">
            <img class="icon" :src="iconInfo.icon8" alt="icon" />
            <span class="font1">联系电话</span>
          </van-col>
          <van-col span="14">
            <span class="font1">{{info.linkTel}}</span>
          </van-col>
        </van-row>
      </div>
    </div>
    <div class="info">
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" :src="iconInfo.icon9" alt="icon" />
            <span class="font1">订单号</span>
          </van-col>
          <van-col span="14">
            <span class="font1">{{info.orderId}}</span>
          </van-col>
        </van-row>
      </div>
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" :src="iconInfo.icon3" alt="icon" />
            <span class="font1">下单时间</span>
          </van-col>
          <van-col span="14">
            <span class="font1">{{info.orderTime}}</span>
          </van-col>
        </van-row>
      </div>
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" :src="iconInfo.icon4" alt="icon" />
            <span class="font1">接单时间</span>
          </van-col>
          <van-col span="14">
            <span class="font1">{{info.receiveOrderTime}}</span>
          </van-col>
        </van-row>
      </div>
      <div>
        <van-row>
          <van-col span="10">
            <img class="icon" :src="iconInfo.icon7" alt="icon" />
            <span class="font1">接单人</span>
          </van-col>
          <van-col span="14">
            <span class="font1">{{info.nickName}}</span>
          </van-col>
        </van-row>
      </div>
    </div>
    <div class="place">
      <div>
        <img class="icon" :src="iconInfo.icon9" alt="icon" />
        <span class="font1">任务地点</span>
      </div>
      <div class="det">
        <div class="font1">{{info.taskAdd}}{{info.taskDtlAddr}}</div>
        <!-- <div class="desc">{{info.taskAdd}}</div> -->
      </div>
    </div>
    <div class="place">
      <div>
        <img class="icon" :src="iconInfo.icon3" alt="icon" />
        <span class="font1">接货地点</span>
      </div>
      <div class="det">
        <div class="font1">{{info.taskReceiveAreaId}}{{info.taskRecAdd}}</div>
        <!-- <div class="desc">{{info.taskReceiveAreaId}}</div> -->
      </div>
    </div>
    <div class="info">
      <div class="flex flex-between flex-middle">
        <div>
          <img class="icon" src="/static/images/errand/icon6.png" alt />
          <span class="font1">任务日期</span>
        </div>
        <span class="time">{{info.taskDate}}</span>
      </div>
      <div class="flex flex-between flex-middle">
        <div>
          <img class="icon" src="/static/images/errand/icon5.png" alt />
          <span class="font1">任务时间</span>
        </div>
        <span class="time">{{info.taskBeginTime}}</span>
      </div>
    </div>
    <!-- 备注 -->
    <div class="remark">
      <van-row>
        <van-col span="3">
          <span class="font1">备注:</span>
        </van-col>
        <van-col span="21">
          <span class="font1">
            {{info.taskRemark}}
          </span>
        </van-col>
      </van-row>
    </div>
    <!-- 参考图片 -->
    <div class="reference">
      <div class="font1">任务参考图片</div>
      <div class="imgs">
        <img v-for="url in imgList" :src="url.imageUrl" alt="img" :key="url.imageUrl" @click="preImg(url.imageUrl)"/>
      </div>
    </div>
    <div class="footer">
        <van-button class="footer-btn" plain type="info" size="small" @click="handleIm(info.publishMemberId)">联系客户</van-button>
        <van-button class="footer-btn" plain type="info" size="small" v-if="info.orderStatus == 3" @click="makeTaskOrder(2, info.orderId)">完成任务</van-button>
        <van-button class="footer-btn" plain type="info" size="small" v-if="info.orderStatus == 2" @click="makeTaskOrder(3, info.orderId)">开始任务</van-button>
        <van-button class="footer-btn" type="info" size="small" v-if="info.orderStatus != 5" @click="makeTaskOrder(4, info.orderId)">放弃任务</van-button>
        <van-button class="footer-btn" type="info" size="small" v-if="info.orderStatus == 5" @click="makeTaskOrder(5, info.orderId)">删除</van-button>
    </div>
  </section>
</template>
<script>
import {cutTime} from '@/utils/filters.js';
const iconInfo = {};
for (let i = 1; i < 10; i++) {
  iconInfo['icon'+i] = require(`@static/images/errand/icon${i}.png`);
}
export default {
  data() {
    return {
      iconInfo,
      info: {},
      imgList: [],
      optionKeys: {
        1: {
          title: '接单',
          desc: '您确定接单吗？'
        },
        2: {
          title: '完成',
          desc: '您确定完成吗？'
        },
        3: {
          title: '开始订单',
          desc: '您确定开始订单吗'
        },
        4: {
          title: '放弃订单',
          desc: '您确定放弃订单吗'
        }
      }
    };
  },
  methods: {
    preImg(url) {
      console.log(url);
      let urls = this.imgList.map((item) => {
        return item.imageUrl
      })
      wx.previewImage({
        current: url, // 当前显示图片的http链接
        urls // 需要预览的图片http链接列表
      })
    },
    routerTo(id) {
      wx.navigateTo({ url: "../runlegdetail/index?id=" + id });
    },
    getDetail(id) {
      this.$api.getTaskOrderDtl({
        orderId: id
      }).then(({data}) => {
        data.taskOrder.taskDate = cutTime(data.taskOrder.taskDate);
        data.taskOrder.orderTime = cutTime(data.taskOrder.orderTime);
        data.taskOrder.receiveOrderTime = cutTime(data.taskOrder.receiveOrderTime);
        this.info = data.taskOrder;
        this.imgList = data.taskOrderImageList;
      })
    },
    //1.接单2.完成 3.开始订单4.放弃订单
    makeTaskOrder(type, orderId){
      const self = this;
      const obj = this.optionKeys[type];
      wx.showModal({
        title: obj.title, //提示的标题,
        content: obj.desc, //提示的内容,
        showCancel: true, //是否显示取消按钮,
        cancelText: "取消", //取消按钮的文字，默认为取消，最多 4 个字符,
        cancelColor: "#000000", //取消按钮的文字颜色,
        confirmText: "确定", //确定按钮的文字，默认为取消，最多 4 个字符,
        confirmColor: "#3BB8FD", //确定按钮的文字颜色,
        success: res => {
          if (res.confirm) {
            self.$api.makeTaskOrder({orderId,type}).then(res => {
                if(res.code == 0){
                  if (type == 4 || type == 5) {
                    wx.navigateBack({
                      delta: 1 // 回退前 delta(默认为1) 页面
                    })
                    return;
                  }
                  self.getDetail(self.info.orderId);
                }
            });
          } else if (res.cancel) {
            console.log("用户点击取消");
          }
        }
      });
    },
    handleIm(id) {
      this.$tim(id)
    },
  },
  onShow() {
    const params = this.$getQuery();
    this.getDetail(params.id);
  }
};
</script>
<style lang="scss" scoped>
.my-runlegdetail {
  padding-bottom: 60px;
  .status {
    background: rgba(255, 255, 255, 1);
    border-radius: 5px;
    margin: 15px 10px;
    padding: 20px 15px;
  }
  .info {
    margin: 15px 10px;
    padding: 0 10px;
    background: rgba(255, 255, 255, 1);
    border-radius: 5px;
    & > div {
      padding: 20px 0;
    }
    & > div:not(:last-child) {
      border-bottom: 1px solid #f2f2f2;
    }
    .icon {
      margin-right: 6px;
    }
    .price {
      font-size: 15px;
      font-family: PingFang;
      font-weight: 500;
      color: rgba(59, 184, 253, 1);
      line-height: 13px;
      vertical-align: middle;
    }
    .time {
      font-size: 12px;
      font-family: DIN;
      font-weight: 500;
      color: rgba(46, 46, 46, 1);
      line-height: 13px;
    }
  }
  .place {
    margin: 15px 10px;
    .font1 {
      margin-left: 6px;
    }
    .det {
      margin-top: 8px;
      padding: 20px;
      background: rgba(255, 255, 255, 1);
      border-radius: 5px;
      .font1 {
        margin-left: 0;
      }
      .desc {
        font-size: 12px;
        font-family: PingFang;
        font-weight: 500;
        color: rgba(193, 196, 201, 1);
        line-height: 13px;
        margin-top: 20px;
      }
    }
  }
  .remark {
    background: rgba(255, 255, 255, 1);
    border-radius: 5px;
    margin: 15px 10px;
    padding: 20px 10px;
    .font1 {
      line-height: 24px;
    }
  }
  .orders {
    margin: 30px 15px;
    background: rgba(59, 184, 253, 1);
    border-radius: 5px;
    font-size: 15px;
    font-family: PingFang;
    font-weight: 500;
    color: rgba(255, 255, 255, 1);
  }
  .reference {
    padding: 15px 10px;
    background: rgba(255, 255, 255, 1);
    border-radius: 5px;
    margin: 15px 10px;
    .font1 {
      margin-bottom: 15px;
    }
    .imgs {
      img {
        width: 60px;
        height: 60px;
        border-radius: 1px;
        background: forestgreen;
        &:not(:last-child){
          margin-right: 9px;
        }
      }
    }
  }
  .font1 {
    font-size: 13px;
    font-family: PingFang;
    font-weight: 500;
    color: rgba(46, 46, 46, 1);
    line-height: 13px;
    vertical-align: middle;
  }
  .icon {
    width: 14px;
    height: 14px;
    vertical-align: middle;
  }
}
.footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 15px;
    background: #fff;
    position: fixed;
    bottom: 0px;
    left: 0px;
    right: 0px;
}
.footer-btn {
    margin-left: 13px;
    /deep/.van-button--info {
        border-color: $theme-color;
        background: $theme-color;
    }
    /deep/.van-button--plain {
        color: $theme-color;
        background: #fff;
    }
}
</style>
<style lang="scss">
page {
  background: #f7f7f7;
}
</style>